/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facadeBonita;

import businessData.Distribution;
import businessData.DistributionPlan;
import businessData.MasterPlan;
import businessData.Order;
import businessData.ProductionPlan;
import businessData.SupplyPlan;
import entities.Material;
import facade.CustomerFacadeRemote;
import facade.CustomerRequestFacadeRemote;
import facade.MaterialFacadeRemote;
import facade.NonWorkingDayFacadeRemote;
import facade.ProductFacadeRemote;
import facade.ProductXsalesFacadeRemote;
import facade.PymeFacadeRemote;
import facade.RequestXproductFacadeRemote;
import facade.SalesFacadeRemote;
import facade.SupplierFacadeRemote;
import facade.SupplierXmaterialFacadeRemote;
import facade.SupplierXpymeFacadeRemote;
import facade.estimator.mrp.EstimatorMRPFacadeRemote;
import facade.mrp.MRPFacadeRemote;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Andrés Felipe
 */
public class BonitaConnection implements InterfaceBonita {
    
    private  Context context;

    public BonitaConnection() {
        context = getContex();
    }
    
    private Context getContex ()
    {
        context = null; 
        try {
            String JBOSS_CONTEXT="org.jboss.naming.remote.client.InitialContextFactory";
            Properties props = new Properties();
            props.put("jboss.naming.client.ejb.context", true);
            props.put(Context.INITIAL_CONTEXT_FACTORY, JBOSS_CONTEXT);
            props.put(Context.PROVIDER_URL, "remote://localhost:4447");
            props.put(Context.SECURITY_PRINCIPAL, "user");
            props.put(Context.SECURITY_CREDENTIALS, "root");
            context = new InitialContext(props);
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }       
        return context;
    }
    
    private List<List<String>> doList(ArrayList<ArrayList<Object>> customerRecuest)
    {
        List<List<String>> list = new ArrayList<List<String>>();    
        for(Object o:customerRecuest)
        {
            if(customerRecuest.indexOf(o) != 0)
            {   
                 List<Object> data = (List<Object>)o;
                 List<String> newdata = new ArrayList<String>();
                 newdata.add(data.get(0).toString());
                 newdata.add(data.get(2).toString());
                 list.add(newdata);    
            }   
        }    
        
        
        return list;    
    }
    
    @Override
    public List<List<String>> getAllPymes() {
        List<List<String>> result = new ArrayList<List<String>>();
        try {      
            PymeFacadeRemote pymeRemote=(PymeFacadeRemote)context.lookup("Javeriana.EJB.Estimator/PymeFacade!facade.PymeFacadeRemote");
            result = pymeRemote.getAllPymes();      
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result; 
    }

    @Override
    public List<String> getCustomerInformation(String customerIdentification, long pymeIdentification) {
           
        List<String> result = new ArrayList<String>();
        try {
            
            CustomerFacadeRemote customerRemote=(CustomerFacadeRemote)context.lookup("Javeriana.EJB.Estimator/CustomerFacade!facade.CustomerFacadeRemote");
            result = customerRemote.getCustomerInformation(customerIdentification, pymeIdentification);
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }  
        return result;
    }

    @Override
    public List<List<String>> getProductsInformation(long pymeIdentification, int toSell) {
        
        List<List<String>> result = new ArrayList<List<String>>();
        int pymeId = Integer.parseInt(String.valueOf(pymeIdentification));
        try {       
            ProductFacadeRemote productRemote=(ProductFacadeRemote)context.lookup("Javeriana.EJB.Estimator/ProductFacade!facade.ProductFacadeRemote");
            result = productRemote.getProductsInformation(pymeId, toSell);                  
 
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }


    @Override
    public void newCustomer(String identification, long pymeIndentification, String name, String adress, String email, String phone) {
       
        int pymeId = Integer.parseInt(String.valueOf(pymeIndentification));
        try {            
            CustomerFacadeRemote CustomerRemote=(CustomerFacadeRemote)context.lookup("Javeriana.EJB.Estimator/CustomerFacade!facade.CustomerFacadeRemote");
            CustomerRemote.newCustomer(identification, pymeId, name, adress, email, phone);
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }      
    }
    
    @Override
    public List<String> getEmailPyme(long pymeIdentification) {
        int idPyme = Integer.parseInt(String.valueOf(pymeIdentification));
        List<String> result = new ArrayList<String>();
        try {      
            PymeFacadeRemote emailPymeRemote=(PymeFacadeRemote)context.lookup("Javeriana.EJB.Estimator/PymeFacade!facade.PymeFacadeRemote");
            result = emailPymeRemote.getEmailPyme(idPyme);
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }   
        return result;
    }
    @Override
    public long getIdRequest (String customerIdentification,long pymeIdentification)
    {
        long idRequest = 0;
        int pymeId = Integer.parseInt(String.valueOf(pymeIdentification));      
        try {
            CustomerRequestFacadeRemote requestRemote = (CustomerRequestFacadeRemote) context.lookup("Javeriana.EJB.Estimator/CustomerRequestFacade!facade.CustomerRequestFacadeRemote");
            idRequest = requestRemote.getIdRequest(customerIdentification, pymeId);  
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return idRequest;
    }
    
    @Override
    public double getQuotePrice(long idRequest,ArrayList<ArrayList<Object>> customerRequest) {
        
        int id = Integer.parseInt(String.valueOf(idRequest));
        double price = 0;
        try {
            RequestXproductFacadeRemote requestXproductRemote = (RequestXproductFacadeRemote) context.lookup("Javeriana.EJB.Estimator/RequestXproductFacade!facade.RequestXproductFacadeRemote");
            price = requestXproductRemote.getQuotePrice(id, customerRequest);
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }   
        return  price;
    }
    
    
    
    @Override
    public List<List<String>> getCustomerPlan(ArrayList<ArrayList<Object>> customerRecuest , long pymeIdentification) {
        int pymeId = Integer.parseInt(String.valueOf(pymeIdentification));
        List<List<String>> result = new ArrayList<List<String>>();
        try {      
            EstimatorMRPFacadeRemote estimatorRemote=(EstimatorMRPFacadeRemote)context.lookup("Javeriana.EJB.Estimator/EstimatorMRPFacade!facade.estimator.mrp.EstimatorMRPFacadeRemote");
            result = estimatorRemote.ProductsPlan(doList(customerRecuest), pymeId);
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }
    
    @Override
    public Date getDateDeliver(List<List<String>> customerPlan) {
        Date date = null;
        try {      
          EstimatorMRPFacadeRemote estimatorRemote=(EstimatorMRPFacadeRemote)context.lookup("Javeriana.EJB.Estimator/EstimatorMRPFacade!facade.estimator.mrp.EstimatorMRPFacadeRemote");
          date = estimatorRemote.getDateDeliver(customerPlan);
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        return date;
    }
    
    @Override
    public boolean verifyDate (long idRequest)
    {
        try {
            CustomerRequestFacadeRemote requestRemote = (CustomerRequestFacadeRemote) context.lookup("Javeriana.EJB.Estimator/CustomerRequestFacade!facade.CustomerRequestFacadeRemote");
            return requestRemote.verifyDate(Integer.parseInt(String.valueOf(idRequest)));  
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return false;
    }

    @Override
    public MasterPlan createProductsPlan(List<List<String>> customerRequestS, long pymeIdentification) {
        int pymeId = Integer.parseInt(String.valueOf(pymeIdentification));
        MasterPlan mp = null;
        List<List<String>> list = new ArrayList<List<String>>();
        if (customerRequestS != null && customerRequestS.size() > 0) {
            list = customerRequestS;
        }
        try {      
            MRPFacadeRemote mrpRemote=(MRPFacadeRemote)context.lookup("Javeriana.EJB.Estimator/MRPFacade!facade.mrp.MRPFacadeRemote");
            mp = mrpRemote.ProductsPlan(list,pymeId);
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        return mp;
    }

    @Override
    public List<List<String>> assignSupplyPlanVariable(MasterPlan masterPlan) {
        SupplyPlan sp = masterPlan.getMySupplyPlan();
        int tam = sp.getSupplyPlanList().size();
        List<List<String>> listsupply = new ArrayList<List<String>>();
        List<String> head = new ArrayList<String>();
        head.add("<b>Nombre</b>");
        head.add("<b>Cantidad</b>");
        head.add("<b>Fecha</b>");
        listsupply.add(head);
        if (tam > 0) {
            for (Order o : sp.getSupplyPlanList()) {
                List<String> newl = new ArrayList<String>();
		newl.add(o.getName());
		newl.add(String.valueOf(o.getQuantity()));
		newl.add(o.getDate().toString());
		listsupply.add(newl);
            }

        }
        return listsupply;
    }

    @Override
    public List<List<String>> assignProductionPlanVariable(MasterPlan masterPlan) {
        ProductionPlan sp = masterPlan.getMyProductionPlan();
	int tam = sp.getProductionPlanList().size();
	List<List<String>> listsupply = new ArrayList<List<String>>();
	List<String> head = new ArrayList<String>();
	head.add("<b>Nombre</b>");
	head.add("<b>Cantidad</b>");
	head.add("<b>Fecha</b>");
	listsupply.add(head);
	if(tam > 0)
	{
	    for(Order o : sp.getProductionPlanList())
	    {		
                List<String> newl = new ArrayList<String>();			
		newl.add(o.getName());
		newl.add(String.valueOf(o.getQuantity()));
		newl.add(o.getDate().toString());		
		listsupply.add(newl);
            }	
	}
	return listsupply;
    }

    @Override
    public List<List<String>> assignDistributionPlanVariable(MasterPlan masterPlan) {
        DistributionPlan sp = masterPlan.getMydistributionPlan();
	int tam = sp.getMyDistributionList().size();
	List<List<String>> listsupply = new ArrayList<List<String>>();
	List<String> head = new ArrayList<String>();
	head.add("<b>Nombre</b>");
	head.add("<b>Cantidad Inventario</b>");
	head.add("<b>Cantidad Producción</b>");
	listsupply.add(head);
        
	if(tam > 0)
	{
	    for(Distribution o : sp.getMyDistributionList())
	    {	
		List<String> newl = new ArrayList<String>();	
	        newl.add(o.getName());
        	newl.add(String.valueOf(o.getQuantityInventory()));
		newl.add(String.valueOf(o.getQuantityProduction()));	
		listsupply.add(newl);
	    }	
	}
	return listsupply;
    }
    
    
    @Override
    public void saveCustomerPurchase(String customerIdentification,long pymeIdentification,double total,Date date, ArrayList<ArrayList<Object>> customerRequest) {
        
        int pymeId = Integer.parseInt(String.valueOf(pymeIdentification));       
        try {      
            SalesFacadeRemote saleRemote=(SalesFacadeRemote)context.lookup("Javeriana.EJB.Estimator/SalesFacade!facade.SalesFacadeRemote");
            int saleId = saleRemote.getSaleId(customerIdentification, pymeId, total, date);
            if (customerRequest.size() > 1) {
                for (ArrayList<Object> o : customerRequest) {
                    if (customerRequest.indexOf(o) != 0) {
                        ArrayList<Object> content = (ArrayList<Object>) o;
                        int productId = Integer.parseInt(String.valueOf(content.get(0)));
                        double quantity = (Double.valueOf(String.valueOf(content.get(2))).intValue());
                        ProductXsalesFacadeRemote productXsalesFacadeRemote=(ProductXsalesFacadeRemote)context.lookup("Javeriana.EJB.Estimator/ProductXsalesFacade!facade.ProductXsalesFacadeRemote");                    
                        productXsalesFacadeRemote.saveCustomerPurchase(saleId, productId, quantity, customerRequest);
                    }
                }
            }
                
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        } 
    }

    @Override
    public void deleteCustomer(String customerIdentification, long pymeIdentification) {
        try {
            CustomerFacadeRemote customerRemote=(CustomerFacadeRemote)context.lookup("Javeriana.EJB.Estimator/CustomerFacade!facade.CustomerFacadeRemote");
            customerRemote.deleteCustomer(customerIdentification, (int)pymeIdentification);
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public List<String> getSupplierInformation(long supplierIdentification) {
        List<String> result = new ArrayList<String>();
        try {
            
            SupplierFacadeRemote supplierRemote = (SupplierFacadeRemote)context.lookup("Javeriana.EJB.Estimator/SupplierFacade!facade.SupplierFacadeRemote");
            result = supplierRemote.getSupplierInformation((int)supplierIdentification);
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }  
        return result;
    }

    @Override
    public void addSupplierToPyme(long pymeIdentification, long supplierIdentification) {
        try {
            
            SupplierXpymeFacadeRemote supplierXpymeRemote = (SupplierXpymeFacadeRemote)context.lookup("Javeriana.EJB.Estimator/SupplierXpymeFacade!facade.SupplierXpymeFacadeRemote");
            supplierXpymeRemote.create((int)pymeIdentification, (int)supplierIdentification);
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public List<List<String>> getSuppliersInformationOfPyme(long pymeIdentification) {
        List<List<String>> result = new ArrayList<List<String>>();
        try {
            
            SupplierXpymeFacadeRemote supplierXpymeRemote = (SupplierXpymeFacadeRemote)context.lookup("Javeriana.EJB.Estimator/SupplierXpymeFacade!facade.SupplierXpymeFacadeRemote");
            result = supplierXpymeRemote.getSuppliersInformation((int)pymeIdentification);
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }

    

    @Override
    public void saveDataMaster(int idProduct, String dataMaster) {
        try {       
            ProductFacadeRemote productRemote=(ProductFacadeRemote)context.lookup("Javeriana.EJB.Estimator/ProductFacade!facade.ProductFacadeRemote");
            productRemote.editDataMaster(idProduct, dataMaster);                  
 
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }

    @Override
    public void addNewProduct(String nombre, String dataMaster, double price, double quantity, double capacity, Date productionAbleDate, double productionTime, int toSell, long pymeIdentification, String typeMaterial) {
        int idPyme = Integer.parseInt(String.valueOf(pymeIdentification));
        Material material = new Material(typeMaterial);
        try {       
            ProductFacadeRemote productRemote=(ProductFacadeRemote)context.lookup("Javeriana.EJB.Estimator/ProductFacade!facade.ProductFacadeRemote");
            productRemote.addProduct(nombre, dataMaster, price,quantity , capacity, productionAbleDate, productionTime, toSell, idPyme , material);
 
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public List<String> findAllMaterials() {
        List<String> materiales = new ArrayList<String>();
        try {       
            MaterialFacadeRemote materialRemote=(MaterialFacadeRemote)context.lookup("Javeriana.EJB.Estimator/MaterialFacade!facade.MaterialFacadeRemote");
            materiales = materialRemote.findAllMaterials();
 
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return materiales;
    }

    @Override
    public List<String> findSuppliersByMaterial(String material, long pymeIdentification) {
        List<String> result = new ArrayList<String>();
        int idPyme = Integer.parseInt(String.valueOf(pymeIdentification));
        try {
            
            SupplierFacadeRemote supplierRemote = (SupplierFacadeRemote)context.lookup("Javeriana.EJB.Estimator/SupplierFacade!facade.SupplierFacadeRemote");
            result = supplierRemote.findSuppliersByMaterial(material, idPyme);
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }  
        return result;
    }

    @Override
    public void saveDefaultSupplier(String supplier,long pymeIdentification) {
        int idPyme = Integer.parseInt(String.valueOf(pymeIdentification));
        String [] infoSupplier = supplier.split("-");
        int idSupplier = Integer.parseInt(infoSupplier[0]);
        
        try {
            
            SupplierXmaterialFacadeRemote supplierXmaterialRemote = (SupplierXmaterialFacadeRemote)context.lookup("Javeriana.EJB.Estimator/SupplierXmaterialFacade!facade.SupplierXmaterialFacadeRemote");
            supplierXmaterialRemote.saveDefaultSupplier(idSupplier,idPyme);
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }  
        
    }

    @Override
    public List<List<Order>> combineSuppliersOrder(List<Order> sourceList) {
        
        List<List<Order>> list = new ArrayList<List<Order>>(); 
        try {      
            MRPFacadeRemote mrpRemote=(MRPFacadeRemote)context.lookup("Javeriana.EJB.Estimator/MRPFacade!facade.mrp.MRPFacadeRemote");
            list = mrpRemote.combineSuppliersOrder(sourceList);
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        return list;
    }

    @Override
    public List<List<String>> splitBatch(List<List<Order>> sourceList) {
        
        List<List<String>> list = new ArrayList<List<String>>(); 
        try {      
            MRPFacadeRemote mrpRemote=(MRPFacadeRemote)context.lookup("Javeriana.EJB.Estimator/MRPFacade!facade.mrp.MRPFacadeRemote");
            list = mrpRemote.splitBatch(sourceList);
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        return list;
    }

    @Override
    public List<List<Order>> notifySuppliers(List<List<String>> sourceList) {
        
        List<List<Order>> list = new ArrayList<List<Order>>(); 
        try {      
            MRPFacadeRemote mrpRemote=(MRPFacadeRemote)context.lookup("Javeriana.EJB.Estimator/MRPFacade!facade.mrp.MRPFacadeRemote");
            list = mrpRemote.notifySuppliers(sourceList);
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        return list;
    }

    @Override
    public void saveNonWorkingDays(long pymeIdentification, List<List<Date>> dates) {
        int idPyme = Integer.parseInt(String.valueOf(pymeIdentification));
        try {      
            NonWorkingDayFacadeRemote nonRemote=(NonWorkingDayFacadeRemote)context.lookup("Javeriana.EJB.Estimator/NonWorkingDayFacade!facade.NonWorkingDayFacadeRemote");
            nonRemote.saveNonWorkingDays(idPyme, dates);
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    @Override
    public void deleteNonWorkingDays(long pymeIdentification, String date)
    {
        int idPyme = Integer.parseInt(String.valueOf(pymeIdentification));
        try {      
            NonWorkingDayFacadeRemote nonRemote=(NonWorkingDayFacadeRemote)context.lookup("Javeriana.EJB.Estimator/NonWorkingDayFacade!facade.NonWorkingDayFacadeRemote");
            nonRemote.deleteNonWorkingDays(idPyme, date);
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    @Override
    public List<List<Date>> findAllNonWorkDay(long pymeIdentification) {
        List<Date> dates = new ArrayList<Date>();
        int idPyme = Integer.parseInt(String.valueOf(pymeIdentification));
        try {      
            NonWorkingDayFacadeRemote nonRemote=(NonWorkingDayFacadeRemote)context.lookup("Javeriana.EJB.Estimator/NonWorkingDayFacade!facade.NonWorkingDayFacadeRemote");
            dates = nonRemote.findAllByPyme(idPyme);
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        List<List<Date>> tableDate = new ArrayList<List<Date>>();
        for (Date date : dates) {
            List<Date> newDate = new ArrayList<Date>();
            newDate.add(date);
            tableDate.add(newDate);
        }
        return tableDate;
    }

    @Override
    public List<List<String>> addProductionListOrders(ArrayList<ArrayList<Object>> customerRequest,long pymeIdendification) {
        int pymeId = Integer.parseInt(String.valueOf(pymeIdendification));
        List<List<String>> list = new ArrayList<List<String>>(); 
        try {      
            MRPFacadeRemote mrpRemote=(MRPFacadeRemote)context.lookup("Javeriana.EJB.Estimator/MRPFacade!facade.mrp.MRPFacadeRemote");
            list = mrpRemote.addProductionListOrders(doList(customerRequest),pymeId);
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        return list;
    }

    @Override
    public List<List<String>> getRequestsToMRP(boolean timer, long pymeId) {
        List<List<String>> list = new ArrayList<List<String>>(); 
        try {      
            MRPFacadeRemote mrpRemote=(MRPFacadeRemote)context.lookup("Javeriana.EJB.Estimator/MRPFacade!facade.mrp.MRPFacadeRemote");
            list = mrpRemote.getRequestsToMRP(timer, Integer.parseInt(String.valueOf(pymeId)));
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        return list;
    }

    @Override
    public List<List<String>> caculateProductionBatches(List<List<String>> productionRequest) {
        List<List<String>> list = new ArrayList<List<String>>(); 
        try {      
            MRPFacadeRemote mrpRemote=(MRPFacadeRemote)context.lookup("Javeriana.EJB.Estimator/MRPFacade!facade.mrp.MRPFacadeRemote");
            list = mrpRemote.caculateProductionBatches(productionRequest);
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
        return list;
    }

    @Override
    public List<String> findAllSuppliers() {
        List<String> result = new ArrayList<String>();
        try {
            
            SupplierFacadeRemote supplierRemote = (SupplierFacadeRemote)context.lookup("Javeriana.EJB.Estimator/SupplierFacade!facade.SupplierFacadeRemote");
            result = supplierRemote.findAllSuppliers();
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }  
        return result; 
    }

    @Override
    public List<String> findAllClients(long pymeIdentification){
        int pymeId = Integer.parseInt(String.valueOf(pymeIdentification));
        List<String> result = new ArrayList<String>();
        try {
            
            CustomerFacadeRemote customerRemote = (CustomerFacadeRemote)context.lookup("Javeriana.EJB.Estimator/CustomerFacade!facade.CustomerFacadeRemote");
            result = customerRemote.findAllClients(pymeId);
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }  
        return result; 
    }

    @Override
    public String getNamePyme(long pymeIdentification) {
        int pymeId = Integer.parseInt(String.valueOf(pymeIdentification));
        String name = "";
        try {
            
            PymeFacadeRemote pymeRemote = (PymeFacadeRemote)context.lookup("Javeriana.EJB.Estimator/PymeFacade!facade.PymeFacadeRemote");
            name = pymeRemote.getNamePyme(pymeId);
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }  
        return name; 
    }

    @Override
    public Integer getIdPyme(String namePyme) {
        Integer id = null;
        try {
            
            PymeFacadeRemote pymeRemote = (PymeFacadeRemote)context.lookup("Javeriana.EJB.Estimator/PymeFacade!facade.PymeFacadeRemote");
               id = pymeRemote.getIdPyme(namePyme);
            
        } catch (NamingException ex) {
            Logger.getLogger(BonitaConnection.class.getName()).log(Level.SEVERE, null, ex);
        }  
        
        return id;
    }
    
    
}
